import socket
from socket import *



class UDPServer:
    def __init__(self):
        self.server_socket = socket(AF_INET, SOCK_DGRAM)
        self.server_socket.setsockopt(SOL_SOCKET,SO_REUSEADDR,1)
        self.server_socket.bind(("127.0.0.1", 2222))
        print("全国最大美女裸聊平台".center(100, "*"))

    def __deal_request(self):
        data, address = self.server_socket.recvfrom(1024)
        temp=data.decode("utf-8").split()
        if temp[0]=="L":
            self.server_socket.sendto("登录成功".encode("utf-8"),address)
            print(f"{temp[1]}进入了群聊")
        elif temp[0]=="C":
            print(f'{temp[1]}:{temp[2]}')
            self.server_socket.sendto("chart".encode("utf-8"),address)

        elif temp[0]=="Q":
            self.server_socket.sendto("你已成功退出".encode("utf-8"), address)
            print(f"用户{temp[1]}退出了群聊")

    def main(self):
        self.__deal_request()


if __name__ == "__main__":
    server = UDPServer()
    while True:
        server.main()
